<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户信息修改</title>
    <link rel="stylesheet" href="css/userinfo_update.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/game_hall.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/common.js"></script>
</head>

<body>
     <!-- 导航栏 -->
    <div class="nav">
      五子棋对战
      <span class="spacer"></span>
      
      <div class="menu-container"> 
          <ul class="menu">
              <li><a href="">menu</a>
                  <ul class="submenu">
                      <li><a href="game_hall.html">返回房间</a></li>
                      <li><a href="user_info.html">个人信息</a></li>
                      <li><a href="Security_setting.html">密保设置</a></li>
                      <li><a href="photo.html">头像设置</a></li>
                      <li><a href="login.html">退出</a></li>
                    </ul>
              </li>
          </ul>
      </div>
  </div>
  <!-- 版心 -->
  <div class="container">
        <div class="card">
          <h3>用户信息修改</h3>
          <div class="row">
              <span>用户名</span>
              <input type="text" id="username">
          </div>
          <div class="row">
            <span>性别 </span>
            <input type="text" id="gender">
          </div>
          <div class="row">
            <span>个人简介 </span>
            <input type="text" id="showself">
          </div>
          <div class="row">
            <span>所在地区 </span>
            <input type="text" id="place">
          </div>
          <div class="row">
            <button id="submit" onclick="mysub()">提交</button>
        </div>
    </div>

    <script>
      //获取个人信息
      function showInfo(){
            jQuery.ajax({
<!--                url:"http://"+ location.host + "/user/showuserinfo",-->

                url:"/user/showuserinfo",
                type:"POST",
                data:{},
                success:function(result){
                    if(result!=null && result.code==200){
                        jQuery("#gender").text(result.data.gender);
                        jQuery("#username").text(result.data.username);
                        jQuery("#showself").text(result.data.showself);
                        jQuery("#place").text(result.data.place);
                      }else{
                        alert("个人信息加载失败，请重新刷新再试！");
                    }
                }
            });
        }
        showInfo();
      function mysub() {
            // 1.非空校验
            var username = jQuery("#username");
            var gender = jQuery("#gender");
            var showself = jQuery("#showself");
            var place = jQuery("#place");
            if (username.val() == null&& gender.val() == null && shiwself.val() == null && place.val() ==null) {
                alert("请重新输入!");
            }
            // 2.ajax 请求登录接口
            jQuery.ajax({
<!--                url: "http://"+ location.host + "/user/updateinfo",-->

                url: "/user/updateinfo",
                type: "POST",
                data: { "username": username.val(),"gender":gender.val(),
                       "showself":showself.val(),"place":place.val()},
                success: function (result) {
                    // 响应的结果
                    if (result != null && result.code == 200 && result.data != null) {
                        location.href = "/user_info.html";
                    } else if (result != null && result.code != 200 && result.data == null) {
                        alert(result.msg);
                    }
                }
            });
        }
    </script>
  </div>
</body>

</html>